const router = require('koa-router')()

router.get('/', async (ctx, next) => {
  await ctx.render('index', {
    title: 'Hello Koa 6!'
  })
})

router.get('/string', async (ctx, next) => {
  ctx.body = 'koa2 string123123'
})

router.get('/json', async (ctx, next) => {
  ctx.body = {
    title: 'koa2 json'
  }
})

router.get('/testAsync', async (ctx, next) => {
  const a = await new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve('a')
    }, 1000)
  });
  const b = await Promise.resolve('123')
  const c = await 'ccc'
  ctx.body = {
    a,
    b,
    c
  }
})

module.exports = router
